"""
    自动取款机系统
    1.用户信息数据源
    2.登录操作
    3.查询余额
    4.取款操作
    5.存款操作
    6.退出系统
    7.交互界面
"""

# 1.用户信息数据源
user_list = {
    '123': {'username': "张三", 'password': '123456', 'money': 10000},
    '456': {'username': "李四", 'password': '111111', 'money': 999},
    '789': {'username': "王五", 'password': '222222', 'money': 1000}
}

# 2.登陆操作
def login():
    global account
    print("=" * 12, "欢迎使用自动取款机", "=" * 12)
    while True:
        user_id = input("请输入您的账号：")
        if user_id in user_list:
            password = input("请输入您的密码：")
            if password == user_list[user_id]['password']:
                print("=" * 16, "登陆成功！", "=" * 16)
                account = user_id
                break
            else:
                print("您输入的密码错误，请重新输入")
                continue
        else:
            print("您输入的账号不存在，请重新输入")
            continue

# 3.查询余额
def check_balance(id):
    print("您的账户余额为：{:16}".format(user_list[id]['money']))

# 4.取款
def draw_money(id):

    draw = eval(input("请输入取款金额："))
    if draw > user_list[id]['money']:
        print("=" * 11, "余额不足！请重新输入", "=" * 11)
    else:
        print("取款成功！")
        user_list[id]['money'] = user_list[id]['money'] - draw
        print("您的账户余额为：{}".format(user_list[id]['money']))

# 5.存款
def deposit_money(id):
    deposit = eval(input("请输入存款金额："))
    print("存款成功！")
    user_list[id]['money'] = user_list[id]['money'] + deposit
    print("您的账户余额为：{}".format(user_list[id]['money']))

# 6.退出系统
def loginout():
    pass

# 7.交互界面
login()
while True:
    print("=" * 12, "欢迎使用自动取款机", "=" * 12)
    print("{:1}{:13}{:13}".format("  ", "1.查询余额", "2.取款"))
    print("{:1}{:15}{:13}".format("  ", "3.存款", "4.退出系统"))
    print("=" * 43)
    key = int(input("请输入对应的选择："))
    if key == 1:
        print("=" * 15, "余额查询界面", "=" * 15)
        check_balance(account)
        input("按回车键回到主页面")
    elif key == 2:
        print("=" * 17, "取款界面", "=" * 16)
        draw_money(account)
        input("按回车键回到主页面")
    elif key == 3:
        print("=" * 17, "存款界面", "=" * 16)
        deposit_money(account)
        input("按回车键回到主页面")
    elif key == 4:
        print("=" * 17, "再见！", "=" * 18)
        loginout()
        break
    else:
        print("=" * 16, "操作无效！", "=" * 16)

